ISSS608-VAA
  • Hands-on Exercise
    • Hands-on Exercise 1
    • Hands-on Exercise 2
    • Hands-on Exercise 4
    • Hands-on Exercise 5 - Corrgram
    • Hands-on Exercise 5 - Ternary
    • Hands-on Exercise 5 - Parallel
  • Take-home Exercise
    • Take-home Exercise 1
    • Take-home Exercise 2
    • Take-home Exercise 3
    • Take-home Exercise 4
  • In-class Exercise
    • In-class Exercise 3
    • In-class Exercise 4
    • In-class Exercise 5 - Corrgram
    • In-class Exercise 5 - Ternary
    • In-class Exercise 5 - Parallel
    • In-class Exercise 8
  • Home
  • About

On this page

  • Average Speed
    • Distribution of Average Speed
    • Comparing mean average speed across gender, strokes, distance, rounds
    • Comparing mean average speed across continents for different stroke, event and gender
    • Correlation between average speed and reaction time; using scatter plot (by gender, event, stroke, race distance and/or round) 
  • Reaction Time
    • Distribution of Reaction Time
    • Comparing mean Reaction Time across continents for different stroke, event and gender

Project

pacman::p_load(tidyverse, lubridate, ggstatsplot, gapminder)
swimdata <- read_csv("data/swimdata_clean.csv")
continents <- read_csv("data/continents.csv")
clean_time <- function(s) {
  ifelse(str_detect(s, ":"), s, paste0("0:", s))
}
swimdata <- left_join(swimdata, continents,
                      by = c('Team'='Nation'))

swimdata <- swimdata %>%
  mutate(Finals_Time2 = period_to_seconds(ms(clean_time(Finals_Time)))) %>%
  mutate(Distance2 = as.numeric(str_replace(Distance, "m", ""))) %>%
  mutate(Average_speed = Distance2/Finals_Time2) %>%
  filter(!Style %in% c('Medley', 'Relay'))

write_csv(
  swimdata,
  "swimdata_clean.csv",
)

Average Speed

Distribution of Average Speed

Shiny: add selection for Gender, Stroke, Distance, Rounds

pacman:: p_load(ggiraph, patchwork)

swimdata$tooltip <- c(paste0(
  'Average Speed = ', swimdata$Average_speed,
  "\n Name = ", swimdata$Name
))

p1 <- ggplot(data=swimdata,
            aes(x=Average_speed))+
  geom_histogram_interactive(bins=60, aes(tooltip=swimdata$tooltip))

p2 <- ggplot(data=swimdata,
             aes(x='', y=Average_speed))+
  geom_boxplot()+
  coord_flip()

p3 <- p2 + p1 + plot_layout(nrow = 2, heights = c(1, 5))

girafe(
  ggobj = p3,
  width_svg = 6,
  height_svg = 6*0.618
)

Comparing mean average speed across gender, strokes, distance, rounds

ggbetweenstats(
  data = swimdata,
  x = Distance, #interactive
  y = Average_speed,
  pairwise.comparisons = FALSE,)+
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1),
            text=element_text(size=12.5)) 

Comparing mean average speed across continents for different stroke, event and gender

p4 <- ggdotplotstats(
  data       = swimdata,
  y          = Continent,
  x          = Average_speed,
  type       = "robust",
  title      = "Distribution of average speed for continent",
  xlab       = "Average Speed",
  ylab.      = "Continent"
)
p4

Correlation between average speed and reaction time; using scatter plot (by gender, event, stroke, race distance and/or round) 

p5 <- ggscatterstats(
  data = swimdata,
  x = Average_speed,
  y = Reaction_Time,
  marginal = FALSE,
  )
p5

Reaction Time

Distribution of Reaction Time

Shiny: add selection for Gender, Stroke, Distance, Rounds

swimdata$tooltip <- c(paste0(
  'Reaction Time = ', swimdata$Reaction_Time,
  "\n Name = ", swimdata$Name
))

p6 <- ggplot(data=swimdata,
            aes(x=Reaction_Time))+
  geom_histogram_interactive(bins=40, aes(tooltip=swimdata$tooltip))

p7 <- ggplot(data=swimdata,
             aes(x='', y=Reaction_Time))+
  geom_boxplot()+
  coord_flip()

girafe(
  ggobj = p7 + p6 + plot_layout(nrow = 2, heights = c(1, 5)),
  width_svg = 6,
  height_svg = 6*0.618
)

Comparing mean average speed across gender, strokes, distance, rounds

p8 <- ggbetweenstats(
  data = swimdata,
  x = Gender, #shiny input
  y = Reaction_Time
)
p8

Comparing mean Reaction Time across continents for different stroke, event and gender

p9 <- ggdotplotstats(
  data       = swimdata, #filter shiny input
  y          = Continent,
  x          = Reaction_Time,
  type       = "robust",
  title      = "Distribution of reaction time for continent",
  xlab       = "Reaction Time",
  ylab.      = "Continent"
)
p9